<!DOCTYPE html>
<html>
<head>
<title>Basic editor functionality tests</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="../js/qunit/reporter.js"></script>
<script src="../js/utils.js"></script>
<script src="../js/tinymce_loader.js"></script>
<script src="../js/jsrobot/robot.js"></script>
<script>
	QUnit.config.reorder = false;
	QUnit.config.autostart = false;

	module('Formatting - Robot Tests', {
		autostart: false
	});
	function checkExpectedAfterNewParagraph(expected) {
		robot.type('\n', false, function() {
			robot.type('g', false, function() {
				var actual = editor.getContent();
				var cleaned = actual.replace("<br />","");
				equal(cleaned, expected);
				start();
			}, editor.getBody())
		}, editor.getBody());
	}
	asyncTest('Should not be bold after turning off bold and going to a new paragraph', function() {
		editor.setContent('<p><strong>text</strong></p>');
		// in order for the robot to work well, we need to focus the editor before performing selection on it.
		editor.focus();
		setSelection("strong",4);
		editor.execCommand("Bold");
		var expected = '<p><strong>text</strong></p>\n<p>g</p>';
		checkExpectedAfterNewParagraph(expected);
	});
	
	asyncTest('Format with nested formatting turned off handled correctly', function(){
		editor.setContent('<p><strong>bold<em>italic<span style="text-decoration: underline;">under</span></em></strong></p>');
		editor.focus();
		setSelection("span",5);
		editor.execCommand("Italic");
		var expected ='<p><strong>bold<em>italic<span style="text-decoration: underline;">under</span></em></strong></p>\n<p><strong><span style="text-decoration: underline;">g</span></strong></p>';
		checkExpectedAfterNewParagraph(expected);
	});

	asyncTest('Format selection over two lines', function(){
		editor.setContent("<div id='a'>one</div><div id='b'>two</div>");
		editor.focus();
		setSelection('#a', 0, '#b', 0);
		editor.execCommand('formatBlock', false, 'h1');
		equal(editor.dom.select('#a')[0].tagName, 'H1');
		equal(editor.dom.select('#b')[0].tagName, 'DIV');
		start();
	});

	var initTinyFunction = function(){
		tinymce.init({
			mode : "exact",
			elements : "elm1",
			cleanup: true,

			add_unload_trigger : false,
			plugins: "table",
			init_instance_callback : function(ed) {
				editor = ed;

			}
		});
	};
</script>
</head>
<body>
<h1 id="qunit-header">Plugin Dependency Functional tests</h1>

<h2 id="qunit-banner"></h2>

<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="content">
	<textarea id="elm1" name="elm1"></textarea>

	<div>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
	</div>
</div>
<script>
	initWhenTinyAndRobotAreReady(initTinyFunction);
</script>
</body>
</html>
